Skip to content

Add SmoothedConstantInterpolation #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

SouthEndMusic
Copy link
Member

@SouthEndMusic SouthEndMusic commented Nov 25, 2024

Fixes #364.

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

using DataInterpolations
using Plots
using Random

N = 10
Random.seed!(8)
u = rand(N)
t = cumsum(rand(N))
A1 = ConstantInterpolation(u, t)

p = plot()
plot!(A1)

for d_max in 00.05:0.05:0.2
    A2 = SmoothedConstantInterpolation(u, t, cache_parameters = true; d_max)
    plot!(A2)
end

p

figure

@SouthEndMusic SouthEndMusic marked this pull request as draft November 25, 2024 15:27
@SouthEndMusic SouthEndMusic marked this pull request as ready for review November 26, 2024 11:43
@SouthEndMusic SouthEndMusic marked this pull request as draft November 26, 2024 11:44
@SouthEndMusic SouthEndMusic marked this pull request as ready for review December 3, 2024 15:10
@SouthEndMusic SouthEndMusic marked this pull request as draft December 3, 2024 15:11
@SouthEndMusic
Copy link
Member Author

Fun feature; if SmoothedConstantInterpolation is used with extrapolation = ExtrapolationType.Periodic, then the transitions are also smooth:

using DataInterpolations
using Plots
using Random

N = 4
Random.seed!(8)
u = rand(N)
t = cumsum(rand(N))
Δt = t[end] - t[1]
t_eval = range(first(t) - Δt, last(t) + Δt, length = 500)

A = SmoothedConstantInterpolation(u, t; extrapolation = ExtrapolationType.Periodic, d_max = 0.2)

plot(t_eval, A.(t_eval))
scatter!(t[1:end-1], u[1:end-1]; label = "data")
scatter!(t[1:end-1] .+ Δt, u[1:end-1]; label = "data one period forward")
scatter!(t[1:end-1] .- Δt, u[1:end-1]; label = "data one period back")

plot

@SouthEndMusic SouthEndMusic marked this pull request as ready for review December 3, 2024 15:37
sathvikbhagavan
sathvikbhagavan previously approved these changes Dec 9, 2024
@ChrisRackauckas
Copy link
Member

Conflicts?

@SouthEndMusic SouthEndMusic marked this pull request as draft April 16, 2025 09:02
@SouthEndMusic
Copy link
Member Author

I don't understand why the derivative tests are failing 🤔

@SouthEndMusic
Copy link
Member Author

fixed it 👍

@ChrisRackauckas
Copy link
Member

I think I'm happy. @sathvikbhagavan ?

Copy link
Member

@sathvikbhagavan sathvikbhagavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of clarifications

@SouthEndMusic
Copy link
Member Author

A tangentially related gripe regarding periodic extrapolation: calendars are a mess, making it difficult to periodically extrapolate timeseries in a way that does not get out of sync with them

sathvikbhagavan
sathvikbhagavan previously approved these changes May 4, 2025
Copy link
Member

@sathvikbhagavan sathvikbhagavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format and then can be merged!

@SouthEndMusic
Copy link
Member Author

@sathvikbhagavan not sure why but formatting locally doesn't make the check pass

@sathvikbhagavan
Copy link
Member

It might be the version. Are you using v1 or v2? CI tries to check in v1

@SouthEndMusic
Copy link
Member Author

That did it 🥳 Btw, is there a way to set compat bounds on packages in your base env?

@ChrisRackauckas
Copy link
Member

SciML/.github#25 let's just get that fixed.

@ChrisRackauckas
Copy link
Member

Let's update the formatting in a follow up, seems like it takes time to propagate.

@ChrisRackauckas ChrisRackauckas merged commit c3d299e into SciML:master May 4, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Smooth equivalent of ConstantInterpolation in terms of integral
3 participants